package cn.com.example.rfid.driver;



public class RfidDriver extends Driver{
	
	private static boolean loadinglib = false;
	
	static {
		try
		{
			System.loadLibrary("jni_rfid_driver");
			loadinglib = true;
		}catch(Throwable ex)
		{
			ex.printStackTrace();
		}
	}

	private native int getTxPower();

	private native int setTxPower(int data);

	private native int init(String ads);

	private native String GetUm7Hw();
	
	private native String GetUm7Fw();
	
	private native int readmore();
	
	private native String stopReadmore();
	
	private native String GetUm7Rssi();
	
	private native String GetUm7Region();
	
	private native int SetUm7Region(int data);
	
	private native String GetDataFromBuf();
	
	private native void StopContinueRead();
	
	private native String NetInit(String ip);

	private native int SetAnt(int Num);

	private native int GetLoss();

	private native String GetAntStatus();

	private native int SetAntMore(int[] ant, int len);

	private native String GetAnt();

	private native float GetTemp();

	private native int SetTempProt(int val);

	private native int GetTempProt();

	private native int DownLoad(String filepath, String filename);

	private native int AntCheck(int[] ant);

	private native int ReSet();

	private native int Close_Uart();

	private native int Write_Epc(String pwd, int ad, int len, String Epc_data);

	private native int Set_Filter(int bank, int ad, int len, String data, boolean save);

	private native int Lock_Tag(String pwd, int bank, int ads, int len, String EpcData, int bankvalue);

	private native int unLock_Tag(String pwd, int bank, int ads, int len, String EpcData, int bankvalue);

	private native int Write_Data(String pwd, int bank, int ads, int len, String data, int bank1, int ads1, int len1, String data1);

	private native String Read_Data(String pwd, int bank, int ads, int len, String data, int bank1, int ads1, int len1);

	private native int Kill(String pwd, int bank, int ads, int len, String data);

	private native int ReadTag_ModelSet(int Model, boolean save);

	private native int ReadTag_ModelGet();

	private native int Inventory_ModelSet(int Model, boolean save);

	private native int Inventory_ModelGet();

	public int initRFID(String dev) {
		if(!loadinglib)
		{
			return -1;
		}

		return init(dev);
	}

	@Override
	public int setTxPowerOnce(final int data) {
		if(data == 0)
		{
			return -1020;
		}
		return setTxPower(data);
	}

	@Override
	public String readUM7hwOnce() {
		return GetUm7Hw();
	}
	
	@Override
	public String readUM7fwOnce() {
		return GetUm7Fw();
	}
	
	@Override
	public int GetTxPower()
	{
		return getTxPower();
	}
	
	@Override
	public int readMore()
	{
		return readmore();
	}
	
	@Override
	public String getRssiOnce()
	{
		return GetUm7Rssi();
	}
	
	@Override
	public String getRegion()
	{
		return GetUm7Region();
	}
	
	@Override
	public String GetBufData()
	{
		return GetDataFromBuf();
	}
	
	@Override
	public void stopRead()
	{
		StopContinueRead();
	}
	
	@Override
	public int SetRegion(int data)
	{
		return SetUm7Region(data);
	}
	
	@Override
	public String Net_Init(String ip)
	{
		return NetInit(ip);
	}

	@Override
	public int GetAntLoss(){
		return GetLoss();
	}

	@Override
	public int Set_Ant(int val){
		return SetAnt(val);
	}

	@Override
	public String Get_AntStatus() {
		return GetAntStatus();
	}

	@Override
	public int Set_Ant_More(int[] ant, int len){
		int[] temp = new int[20];
		for(int i = 0; i < ant.length; i++) {
			temp[i] = ant[i];
		}
		return SetAntMore(temp, temp.length);
	}

	@Override
	public String Get_Ant(){
		return GetAnt();
	}

	@Override
	public float Get_Temp(){
		return GetTemp();
	}

	@Override
	public int Set_TmpProt(int val){
		return SetTempProt(val);
	}

	@Override
	public int Get_TmpProt(){
		return GetTempProt();
	}

	@Override
	public int Down_LoadFw(String filePath, String fileName){
		return DownLoad(filePath, fileName);
	}

	@Override
	public int Ant_Check(int[] ant){
		int[] temp = new int[10];
		for(int i = 0; i < ant.length; i++) {
			temp[i] = ant[i];
		}
		return AntCheck(temp);
	}

	@Override
	public int Reset(){
		return ReSet();
	}

	@Override
	public int Close_Com(){
		return Close_Uart();
	}

	@Override
    public int Write_Epc_Data(String pwd, int ads, int len, String EpcData){
	    return Write_Epc(pwd, ads, len, EpcData);
    }

    @Override
	public int Set_Filter_Data(int bank, int ads, int len, String data, boolean save){
		return Set_Filter(bank, ads, len, data, save);
	}

	@Override
	public int Lock_Tag_Data(String pwd, int bank, int ads, int len, String EpcData, int bankvalue){
		return Lock_Tag(pwd, bank, ads, len, EpcData, bankvalue);
	}

	@Override
	public int unLock_Tag_Data(String pwd, int bank, int ads, int len, String EpcData, int bankvalue){
		return unLock_Tag(pwd,bank, ads, len, EpcData, bankvalue);
	}

	@Override
	public int Write_Data_Tag(String pwd, int bank, int ads, int len, String data, int bank1, int ads1, int len1, String data1){
		return Write_Data(pwd, bank, ads, len, data, bank1, ads1, len1, data1);
	}

	public String Read_Data_Tag(String pwd, int bank, int ads, int len, String data, int bank1, int ads1, int len1){
		return Read_Data(pwd, bank, ads, len, data, bank1, ads1, len1);
	}

	public int Kill_Tag(String pwd, int bank, int ads, int len, String data){
		return Kill(pwd, bank, ads, len, data);
	}

    @Override
    public boolean Read_Tag_Mode_Set(int Model, boolean save) {

		int res = ReadTag_ModelSet(Model, save);

		if(1 == res){
			return true;
		}
		return false;
    }

	@Override
	public int Read_Tag_Mode_Get() {
		return ReadTag_ModelGet();
	}

	@Override
	public boolean Inventory_Model_Set(int Model, boolean save) {

		int res = Inventory_ModelSet(Model, save);

		if(1 == res){
			return true;
		}
		return false;
	}

	@Override
	public int Inventory_Model_Get() {
		return Inventory_ModelGet();
	}
}
